package com.snap.vseries.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.snap.vseries.base.BaseFragment;

import java.util.List;

/**
 * Description:适合Fragment数量较少情况，不适用于fragment列表顺序改变，中间添加fragment或者删除某个fragment的情形
 * Data: 2019/7/2
 *
 * @author: cqian
 */
public class CommenPagerAdapter extends FragmentPagerAdapter {
    private List<? extends BaseFragment> mFragments;
    private String[] mTabText;

    public CommenPagerAdapter(FragmentManager fm, List<? extends BaseFragment> fragments) {
        super(fm);
        this.mFragments = fragments;
    }

    public CommenPagerAdapter(FragmentManager fm, List<? extends BaseFragment> fragments, String[] tabText) {
        super(fm);
        this.mFragments = fragments;
        mTabText = tabText;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mTabText != null && mTabText.length > 0) {
            return mTabText[position];
        }
        return super.getPageTitle(position);
    }
}
